import java.util.Scanner;

public class Test2 {
    //434. 字符串中的单词数
    public int countSegments(String s) {
        String[] str = s.split(" ");
        int count = 0;
        for (int i = 0; i < str.length; i++) {
            if (str[i].length() != 0) {
                count++;
            }
        }
        return count;
    }

    //709. 转换成小写字母
    public String toLowerCase1(String s) {
        String ret = "";
        for(int i = 0; i < s.length(); i++) {
            if (s.charAt(i) <= 'Z' && s.charAt(i) >= 'A') {
                ret += (char)(s.charAt(i) + 32);
            } else {
                ret += s.charAt(i);
            }
        }
        return ret;
    }


    public String toLowerCase(String s) {
        StringBuilder sb = new StringBuilder();
        for(int i = 0; i < s.length(); i++) {
            if (s.charAt(i) <= 'Z' && s.charAt(i) >= 'A') {
                sb.append((char)(s.charAt(i) + 32));
            } else {
               sb.append(s.charAt(i));
            }
        }
        return sb.toString();
    }


    public static void main1(String[] args) {
        String s1="abc"+"def";//1
        String s2 = s1;//2
        if(s1.equals(s2))//3
            System.out.println(".equals succeeded");//4
        if(s1==s2)//5
            System.out.println("==succeeded");//6
    }

    public static void main2(String[] args) {
        String s1="abc"+"def";//1
        String s2 = new String(s1);//2
        if(s1.equals(s2))//3
            System.out.println(".equals succeeded");//4
        if(s1==s2)//5
            System.out.println("==succeeded");//6
    }

    //387. 字符串中的第一个唯一字符
    //只包含小写字母
    public int firstUniqChar(String s) {
        char[] array = new char[26];
        for (int i = 0; i < s.length(); i++) {
            array[s.charAt(i) - 97]++;
        }
        for (int i = 0; i < s.length(); i++) {
            if (array[s.charAt(i) - 97] == 1){
                return i;
            }
        }
        return -1;
    }

    //HJ1 字符串最后一个单词的长度
    public static void test(String[] args) {
        Scanner in = new Scanner(System.in);
        String str = in.nextLine();

        System.out.println(str.subSequence(str.lastIndexOf(' ') + 1, str.length()).length());
    }

    //125. 验证回文串
    public static boolean isDigitLetter(char ch) {
        if(('0' <= ch && ch <= '9') || ('a' <= ch && ch <= 'z')) {
            return true;
        }
        return false;
    }

    public static boolean isPalindrome(String s) {
        s = s.toLowerCase();
        int left = 0;
        int right = s.length() - 1;
        while (left < right) {
            while (left < right && !isDigitLetter(s.charAt(left))) {
                left++;
            }
            while (left < right && !isDigitLetter(s.charAt(right))) {
                right--;
            }
            if (s.charAt(left) != s.charAt(right)) {
                return false;
            } else {
                left++;
                right--;
            }
        }
        return true;
    }

    public static void main3(String[] args) {
        String str1 = "A man, a plan, a canal: Panama";
        boolean ret = isPalindrome(str1);
        System.out.println(ret);
    }
}
